/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Common;

import Views.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.ImageIcon;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

/**
 *
 * @author KIENLT
 */
public class FileMenu implements ActionListener{
    public String userId;
    public FileMenu(String strUserID) {
        this.userId = strUserID;
    }

    public FileMenu(){}
    
    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getActionCommand().equals("Users")){
            Users u = new Users(null, true);
            u.setVisible(true);
        }
        if(e.getActionCommand().equals("Supplier")){
            Suppliers s = new Suppliers(null, true);
            s.setVisible(true);
        }
        if(e.getActionCommand().equals("Category")){
            Categories c = new Categories(null, true);
            c.setVisible(true);
        }
        if(e.getActionCommand().equals("Items")){
            Items i = new Items(null, true);
            i.setVisible(true);
        }
        if(e.getActionCommand().equals("Create Bills")){
            Bills i = new Bills(null, false);
            i.setUserId(userId);
            i.setVisible(true);
        }
        if(e.getActionCommand().equals("Order")){
           // BillsDetail bd = new BillsDetail(null, true);
           // bd.setVisible(true);
//            Order i = new Order(null, true);
//            i.setVisible(true);
        }
        if(e.getActionCommand().equals("Customer")){
            Customer i = new Customer(null, true);
            i.setVisible(true);
        }
        if(e.getActionCommand().equals("Exit")){
            System.exit(0);
        }
        
        
    }
    
    public JMenuBar jMenuBar(ClassLoader cl){
        JMenuBar jmenuBar = new JMenuBar();
        FileMenu fileMenu = new FileMenu(userId);
        
        /**
         *  Menu System
         */
        JMenu menuSystem = new JMenu(Constant.getBundle().getString("system"));
        JMenuItem info = new JMenuItem(Constant.getBundle().getString("information"));
        JMenuItem changepass = new JMenuItem(Constant.getBundle().getString("changepass"));
        JMenuItem exit = new JMenuItem(Constant.getBundle().getString("exit"));
        
        info.addActionListener(fileMenu);
        changepass.addActionListener(fileMenu);
        exit.addActionListener(fileMenu);
//        ImageIcon i = new ImageIcon(cl.getResource("Images\\img_x48\\gnome_mail_mark_unread.png"));
//        info.setIcon(i);
        menuSystem.add(info);
        menuSystem.add(changepass);
        menuSystem.add(exit);
        
        /**
         *  Menu User
         */
        JMenu menuManager = new JMenu(Constant.getBundle().getString("manager"));
        JMenuItem addUser = new JMenuItem(Constant.getBundle().getString("adduser"));
        JMenuItem addSupplier = new JMenuItem(Constant.getBundle().getString("addsupplier"));
        JMenuItem addCategory = new JMenuItem(Constant.getBundle().getString("addcategory"));
        JMenuItem addItem = new JMenuItem(Constant.getBundle().getString("additem"));
        JMenuItem addCustomer = new JMenuItem(Constant.getBundle().getString("addcustomer"));
        
        addUser.addActionListener(fileMenu);
        addSupplier.addActionListener(fileMenu);
        addCategory.addActionListener(fileMenu);
        addItem.addActionListener(fileMenu);
        addCustomer.addActionListener(fileMenu);
        
        menuManager.add(addUser);
        menuManager.add(addSupplier);
        menuManager.add(addCategory);
        menuManager.add(addItem);
        menuManager.add(addCustomer);
        /**
         *  Bills Order
         */
        JMenu bills = new JMenu(Constant.getBundle().getString("bills"));
        JMenuItem createBills = new JMenuItem(Constant.getBundle().getString("createbills"));
        JMenuItem order = new JMenuItem(Constant.getBundle().getString("order"));
        
        createBills.addActionListener(fileMenu);
        order.addActionListener(fileMenu);
        
        bills.add(createBills);
        bills.add(order);
        
        /*
         * 
         */
        jmenuBar.add(menuSystem);
        jmenuBar.add(menuManager);
        jmenuBar.add(bills);
        
        return jmenuBar;
    }
}
